package gui;

import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;
import javax.swing.JButton;

import common.ChatIF;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

public class CommitteeMemberPanel extends JPanel implements ChatIF{
	private AcademicFrame frame;
	private AssessorPanel assessor;
	private MainWindow mainWindow;
	private ReviewAndDecisionPanel reviewAndDecision;
	private boolean isChairman;
	private String userID;
	public CommitteeMemberPanel myself;
	private AssignInspectorPanel assignInspector;
	private JButton btnAssignInspector;
	private InspectPanel inspectionPanel;
	
	
	public CommitteeMemberPanel(AcademicFrame frame, MainWindow mainWindow, boolean isChairman, String userID)
	{
		super();
		this.frame=frame;
		this.mainWindow=mainWindow;
		this.isChairman=isChairman;
		this.userID=userID;
		myself = this;
		frame.setSize(500, 400);
		initialize();
	}
	
	private void initialize()
	{
		setLayout(null);
		
		JLabel lblControlCommitteeMember = new JLabel("Control Committee Member");
		lblControlCommitteeMember.setForeground(Color.BLUE);
		lblControlCommitteeMember.setFont(new Font("Tahoma", Font.BOLD, 28));
		lblControlCommitteeMember.setBounds(31, 38, 396, 22);
		add(lblControlCommitteeMember);
		
		JButton btnInspect = new JButton("Inspect");
		btnInspect.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent arg0)
			{
				inspectionPanel = new InspectPanel(frame, myself);
				frame.setSize(640, 540);
				frame.setContentPane(inspectionPanel);
				
				ArrayList<Object> getListForInspection = new ArrayList<Object>();
				getListForInspection.add("getlistOfInspectionableRequests");	
				getListForInspection.add(userID);
				AcademicFrame.myclient.sendMessageToServer(getListForInspection);
			}
		});
		btnInspect.setBounds(31, 130, 176, 23);
		add(btnInspect);
		if(isChairman)
			btnInspect.setEnabled(true);
		else
			btnInspect.setEnabled(false);
		
		JButton btnReviewAndDecision = new JButton("Review and Decision");
		btnReviewAndDecision.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent e) 
			{
				ArrayList<Object> getUserInformation = new ArrayList<Object>();
				getUserInformation.add("getInfo");
				getUserInformation.add(userID);
				AcademicFrame.myclient.sendMessageToServer(getUserInformation);
								
			}
		});
		btnReviewAndDecision.setBounds(251, 130, 176, 23);
		add(btnReviewAndDecision);
		
		JButton btnBack = new JButton("Back");
		btnBack.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.setSize(500, 500);
				frame.setContentPane(mainWindow);
			}
		});
		btnBack.setBounds(178, 239, 89, 23);
		add(btnBack);
		
		btnAssignInspector = new JButton("Assign Inspector");
		btnAssignInspector.setEnabled(false);
		btnAssignInspector.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				assignInspector = new AssignInspectorPanel(frame, myself);
				frame.setSize(640, 540);
				frame.setContentPane(assignInspector);
				
				ArrayList<Object> getListOfRequestsForInspection = new ArrayList<Object>();
				getListOfRequestsForInspection.add("getListOfRequestsForInspection");	
				getListOfRequestsForInspection.add("11");
				AcademicFrame.myclient.sendMessageToServer(getListOfRequestsForInspection);
				
			}
		});
		btnAssignInspector.setBounds(149, 176, 156, 23);
		add(btnAssignInspector);
		
		if (isChairman)
			btnAssignInspector.setEnabled(true);
			
	}

	@Override
	public void display(Object message)
	{

		ArrayList<Object> answer = new ArrayList<Object>();
		answer = (ArrayList<Object>)message;
		
		if (	((String)(answer.get(0))).equalsIgnoreCase("userInfo")	)
		{
			
				String firstAndLastName = new String ((String)answer.get(1) + " " + (String)answer.get(2));
				
				this.reviewAndDecision = new ReviewAndDecisionPanel(frame, myself,firstAndLastName, isChairman);
				frame.setSize(640, 540);
				frame.setContentPane(reviewAndDecision);
				
				ArrayList<Object> getListOfRequestsForReview = new ArrayList<Object>();
				getListOfRequestsForReview.add("getListOfRequestsForReview");	
				AcademicFrame.myclient.sendMessageToServer(getListOfRequestsForReview);
				
				
			

		}


	}

}
